home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
fbuilder
/
c
/
fbcalc.h
Wrap
C/C++ Source or Header
|
1996-09-15
|
14KB
|
428 lines
/*
*
* C/C++ Header File for FORMULA BUILDER Version 1.0
* An Advanced Expression Parsing/Evaluation Engine
* YGB Software, Inc.
* Copyright (c) 1995, Clayton Collie, All Rights Reserved
*
*/
#ifndef __FB_H__
#define __FB_H__
#ifndef _INC_WINDOWS
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#define FB_VERSION 0x0100
typedef LONG HEXPR; /* expression handle type */
typedef int FBERROR; /* Formula Builder Error Type */
#define CALLBACK FAR PASCAL _export
#define FBAPI FAR PASCAL _export
#define MAXFUNCPARAMS 16 /* Functions can have up to MAXFUNCPARAMS parameters */
/*
*
* Definitions of types handled by Formula Builder
*
*/
typedef BYTE datatypes;
typedef BYTE BOOLEAN;
typedef double FLOAT; /* FormulaBuilder floating point type */
/*
* Dates are stored as a floating point value whose integer portion represents
* the number days elapsed since 01/01/001. The time of day, when time functions
* are implemented, will be represented by the fractional part.
*
*/
typedef double TFBDate, TFBDATE, FAR *LPFBDATE;
/*
* Declaration of the internal FB string type - a pointer to a byte-string,
* a string in which the first byte designates the length, followed by the
* string data (which is limited to 255 characters). Use the utility routines
* to deal with this type
*
*/
typedef char FBString[256];
typedef FBString *TFBSTRING, FAR *LPFBSTRING;
/* NOTE!!!! the following are NOT contiguous */
#define vtINTEGER 0
#define vtBOOLEAN 1
#define vtCHAR 2 /* unused */
#define vtFLOAT 3
#define vtSTRING 4
#define vtPOINTER 5
#define vtDATE 9
#define vtBOOL 10
#define vtANY 11
#define vtNONE 13
#define vtTYPECLASH 14
#define vtTYPEMISMATCH vtTYPECLASH
/* General value structure */
typedef struct tagTValueRec {
BYTE flags;
BYTE vtype;
union {
LONG vInteger;
BOOLEAN vBoolean;
FLOAT vFloat; /* double */
TFBSTRING vpString;
LPVOID vPointer;
TFBDATE vDate;
BOOL vBool;
}
} TVALUEREC,TValueRec,*PVALUEREC,FAR *LPVALUEREC;
/*
*
* Error Codes
*
*/
#define INVALID_VARIABLE -9999 /* Arbitrary but (hopefully) unique - return this from */
// Defines for Error Codes
#define EXPR_SUCCESS 1
#define EXPR_MISSING_PAREN 2
#define EXPR_BAD_EXPRESSION 3
#define EXPR_BAD_ASSIGNMENT 4
#define EXPR_UNKNOWN_IDENT 5
#define EXPR_LINE_TOO_LONG 6
#define EXPR_INVALID_TOKEN 7
#define EXPR_INVALID_CHAR 8
#define EXPR_MISSING_PARAM 9
#define EXPR_TYPE_MISMATCH 10
#define EXPR_INVALID_NUMBER 11
#define EXPR_MISSING_VARIABLE 12
#define EXPR_INVALID_VARIABLE 12
#define EXPR_INVALID_FUNCTION 13
#define EXPR_ZERO_DIVISION 14
#define EXPR_STACK_OVERFLOW 15
#define EXPR_UNEXPECTED_EOS 16
#define EXPR_INVALID_DATE 17
#define EXPR_IDENTIFIER_EXPECTED 18
#define EXPR_RANGE_ERROR 19
#define EXPR_DOMAIN_ERROR 20
#define EXPR_MATH_ERROR 21
#define EXPR_FP_OVERFLOW 22
#define EXPR_FP_UNDERFLOW 23
#define EXPR_INT_OVERFLOW 24
#define EXPR_INVALID_OP 25
#define EXPR_VARIABLE_EXPECTED 26
#define EXPR_MISSING_OPERATOR 27
#define EXPR_MISSING_OPERAND 28
#define EXPR_CONSTANT_EXPECTED 29
#define EXPR_DUPLICATE_IDENT 30
#define EXPR_SYNTAX_ERROR 31
#define EXPR_CONVERT_ERROR 32
#define EXPR_INVALID_TYPE 33
#define EXPR_INVALID_HANDLE 50
#define EXPR_INVALID_CALLBACK 51
#define EXPR_FORMULA_TOO_COMPLEX 54
#define EXPR_INVALID_VARIABLE EXPR_MISSING_VARIABLE
/*
*
* Callback definitions for variable & field implementation
*
*/
typedef FBERROR (CALLBACK *TCBKFindVariable)(LPSTR varname,LPBYTE vtype,LONG vardata,LONG CBKData);
typedef FBERROR (CALLBACK *TCBKGetVariable)(LPSTR varname,LPVALUEREC value,LONG vardata,LONG CBKData);
typedef FBERROR (CALLBACK *TCBKSetVariable)(LPSTR varname,TVALUEREC value,LONG vardata,LONG CBKData);
/*
* function enumeration Callback. See FBEnumFunctions
*/
typedef FBERROR (CALLBACK *TCBKEnumFunctions)(LPSTR vname,BYTE vtype,LPSTR parms,BYTE minPrms,LONG EnumData);
/******************************************************
*
* Declarations for external function implementation
*
******************************************************/
/*
* Actual parameter list passed to external function callback
* The parser engine ensures that these match, in number and
* type, the prototype specified when the callback was registered
*/
typedef TVALUEREC TActParamList[MAXFUNCPARAMS];
typedef TActParamList *PActParamList,FAR *LPPARAMLIST;
/*::::::::::::::::::::::::::::::::::::::::::::::::::::
Prototypes for external user-defined functions
Implemented routine must be exportable
::::::::::::::::::::::::::::::::::::::::::::::::::::*/
typedef void (CALLBACK *TCBKExternalFunc)(BYTE paramcount, \
LPPARAMLIST params, \
LPVALUEREC retvalue, \
LPINT errcode, \
LONG lExprData);
/*:::::::::::::::Engine initialization and shutdown:::::::::::::*/
HEXPR FBAPI FBInitExpression(LONG lExprData);
FBERROR FBAPI FBFreeExpression(HEXPR handle);
/*::::::::::::::::::::: Expression Manipulation ::::::::::::::::*/
FBERROR FBAPI FBSetExpression(HEXPR handle,LPSTR expr);
FBERROR FBAPI FBReparseExpression(HEXPR handle);
FBERROR FBAPI FBClearExpression(HEXPR handle);
FBERROR FBAPI FBGetExpression(HEXPR handle,LPSTR expr,WORD maxlen);
/*==========================================================================
*
* EXPRESSION EVALUATION ROUTINES
*
*=========================================================================*/
/* determine the result type of the expression. Returns one of the
vtXXX constants, vtTYPEMISMATCH for an invalid expression */
FBERROR FBAPI FBGetReturnType(HEXPR handle);
/*
Evaluate the expression, returning a maximum of maxlen characters
of the null-terminated string result in the buffer/string pointed to
by outbuf */
FBERROR FBAPI FBEvaluate(HEXPR handle,LPSTR lpszBuf,WORD wBuflen);
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Evaluate the expression, returning the result in a TValueRec structure
FBFreevalue should be used to dispose of any memory associated with value
when it is no longer needed
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
FBERROR FBAPI FBEvaluatePrim(HEXPR handle,LPVALUEREC value);
/* Dispose of any memory associated with a TValueRec structure */
void FBAPI FBFreeValue(LPVALUEREC value);
/*
*
*
*
*/
FBERROR FBAPI FBGetStringResult(HEXPR handle,LPSTR value,WORD maxlen);
FBERROR FBAPI FBGetFloatResult(HEXPR handle,LPDOUBLE value);
FBERROR FBAPI FBGetBooleanResult(HEXPR handle,LPBOOL value);
FBERROR FBAPI FBGetIntResult(HEXPR handle,LPLONG value);
FBERROR FBAPI FBGetDateResult(HEXPR handle,LPFBDATE value);
/*
Perform a single operation expression evaluation. This is not the most
efficient method of evaluation when the expression remains the same */
FBERROR FBAPI FBEvalExpression(LPSTR expr,LPBYTE retType,LPSTR buf,WORD maxlen);
/*:::::::